package com.jt.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.jt.pojo.Item;
import com.jt.pojo.ItemDesc;
import com.jt.service.DubboItemService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author Cx
 * @stage JT Of Fourth stage
 * @creat 2020-12-16 10:59
 */
@Controller
public class ItemController {

    @Reference(check = false) // 启动时是否校验有服务的提供者
    private DubboItemService itemService;

    // 实现商品id查询商品信息
    @RequestMapping("/items/{itemId}")
    public String findItemById(@PathVariable Long itemId, Model model) {
        Item item = itemService.findItemById(itemId);
        ItemDesc itemDesc = itemService.findItemDescById(itemId);
        // 利用model将数据传递到页面中
        model.addAttribute("item", item);
        model.addAttribute("itemDesc", itemDesc);
        // 跳转商品展现页面
        return "item";
    }

}
